from sqlalchemy import String, Column, ForeignKey, DateTime, func, Integer, Text
from sqlalchemy.orm import relationship

from database import db
from .gateway import Gateway


class FundChannel(db.Model):
    id = Column(String(80), primary_key=True)
    gateway_id = Column(ForeignKey(Gateway.id), doc='所使用的网关', nullable=False)
    status = Column(String(20), default='enabled', nullable=False)
    name = Column(String(200), nullable=False)
    description = Column(String(400), nullable=True, doc='资金源描述')
    order_mode = Column(String(400), nullable=True, doc='订单号生成方式')
    created_at = Column(DateTime, default=func.now())
    updated_at = Column(DateTime, default=func.now())

    gateway = relationship(Gateway)

    STATUS_ENABLED = 'enabled'


class FundChannelConfig(db.Model):
    id = Column(Integer, primary_key=True, autoincrement=True)
    fund_channel_id = Column(ForeignKey(FundChannel.id), nullable=False)
    value = Column(String(400), doc='属性值', nullable=False)
    name = Column(String(200), doc='属性名称', nullable=False)
    value_mode = Column(String(200), doc='属性值类型')
    value_separator = Column(String(10), doc='属性值分隔符')
    remark = Column(Text, doc='备注')

    fund_channel = relationship(FundChannel)
